//
//  BusStopDetailViewController.m
//  Bus_iPhone
//
//  Created by antunnel on 12-7-2.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "BusStopDetailViewController.h"

@interface BusStopDetailViewController ()

@end

@implementation BusStopDetailViewController


@synthesize stopName=_stopName;
@synthesize lineList=_lineList;

-(void)dealloc{

    [_stopName release];
    [_lineList release];
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setCustomNavigationReturnItem];
    
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark -UITableViewDataSource

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    return [NSString stringWithFormat:@"经过 %@ 的站点有:",_stopName];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return _lineList.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellString=@"pass line list";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellString];
    
    if (!cell) {
        cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellString] autorelease];
        cell.backgroundColor=[UIColor clearColor];
    }
    NSDictionary *dic=[_lineList objectAtIndex:indexPath.row];
    NSString *text=nil;
    NSString *lineType=[dic objectForKey:@"type"];
    NSString *lineName=[dic objectForKey:@"lineName"];
    if ([lineType isEqualToString:@"0"]) {
        text=[NSString stringWithString:lineName];
    }else if ([lineType isEqualToString:@"-1"]) {
        text=[NSString stringWithFormat:@"%@ 下行",lineName];
    }else if ([lineType isEqualToString:@"1"]) {
        text=[NSString stringWithFormat:@"%@ 上行",lineName];
    }
    
    cell.textLabel.text=text;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    NSDictionary *dic=[_lineList objectAtIndex:indexPath.row];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"BusLineDetailNotination" object:dic];
}

@end
